[jsp例题]为什么不能插入数据呢..哭了...

来源:百度知道 编辑:UC知道 时间:2024/06/18 13:48:19
<html>
<head>
<title>信息查询系统</title>
</head>

<%@page contentType="text/html; charset=GB2312"%>
<body>
<h1 align="center" class="style1">信息查询系统 </h1>

<form name="form1" method="post" action="insert.jsp">

<p>
姓名:
<input type="text" name="names">
电话:
<input type="text" name="phone">
<input type="submit" name="Submit" value="插入">
</p>

</form>

<p align="left" class="style1">  </p>
</body>
</html>

---------------------- insert.jsp ---------------------

<%@ page import="java.sql.*" %>
<%@ page contentType="text/html;char

对,你的sql写错了。
String insert = "INSERT INTO worker"
+"(names,phone)"
+"VALUES('name','phone')";
的结果是
INSERT INTO worker (names,phone)
VALUES('name','phone')

看出问题了吗?
你需要的是将变量name和phone的值存入数据库而不是字符串"name"和"phone"
正确的写法是:
String insert = "INSERT INTO worker"
+"(names,phone)"
+"VALUES('" + name " + "','" + phone + "')";